package org.gruposp2p.proyectokarma.domain;

//import javax.persistence.Lob;
import java.sql.Clob;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import static javax.persistence.GenerationType.IDENTITY;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Indexed
@Entity
@Table(name="Peer")
public class Peer  implements java.io.Serializable {

	 private static Logger logger = LoggerFactory.getLogger(Peer.class);

	 private static final long serialVersionUID = 1L;
		
     @Id @GeneratedValue(strategy=IDENTITY)
     @Column(name="id", unique=true, nullable=false)
     @DocumentId
     private Long id;
     @Column(name="name")
     @Field
     private String name;
     @Column(name="username", nullable=false, unique=true)
     private String username;
     @Column(name="phone", length=50)
     private String phone;
     @Column(name="url", length=50)
     private String url;
     @Column(name="email", unique=true)
     private String email;
     @Temporal(TemporalType.TIMESTAMP)
     @Column(name="dateCreated", nullable=false, length=23)
     private Date dateCreated = new Date();
     @Temporal(TemporalType.TIMESTAMP)
     @Column(name="lastEntryDate", length=23)
     private Date lastEntryDate;
     @Column(name="password")
     private String password;
     @Column(name="accountExpired")
     private boolean accountExpired;
     @Column(name="accountLocked")
     private boolean accountLocked;
     @Column(name="passwordExpired")
     private boolean passwordExpired;
     @Column(name="enabled")
     private boolean enabled;
     @Column(name="details")
     private Clob details;
     //@Column(name="image")
     //@Lob private byte[] image;
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="peerFrom")
     private Set<Vote> votes = new HashSet<Vote>(0);
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="peer")
     private Set<Document> documents = new HashSet<Document>(0);
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="peer")
     private Set<PeerKarmaParameter> peerKarmaParameters = new HashSet<PeerKarmaParameter>(0);
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="peer")
     private Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>(0);
     private String version;
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="user")
     private Set<PeerRole> peerRole = new HashSet<PeerRole>(0);
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="peer")
     private Set<KarmaFile> karmaFiles = new HashSet<KarmaFile>(0);

     public Peer() { }
     
     public Peer(String email) { 
    	 this.email = email;
     }

     public Long getId() {
         return this.id;
     }
    
     public void setId(Long id) {
         this.id = id;
     }
    
     public String getUsername() {
         return this.username;
     }
    
     public void setUsername(String username) {
        this.username = username;
     }
    
     public String getPhone() {
         return this.phone;
     }
    
     public void setPhone(String phone) {
         this.phone = phone;
     }
    
     public String getUrl() {
         return this.url;
     }
    
     public void setUrl(String url) {
         this.url = url;
     }
    
     public String getEmail() {
         return this.email;
     }

     public void setEmail(String email) {
         this.email = email;
     }

     public Date getDateCreated() {
         return this.dateCreated;
     }
    
     public void setDateCreated(Date dateCreated) {
         this.dateCreated = dateCreated;
     }

     public Date getLastEntryDate() {
         return this.lastEntryDate;
     }

     public void setLastEntryDate(Date lastEntryDate) {
         this.lastEntryDate = lastEntryDate;
     }
    
     public String getPassword() {
        return this.password;
     }
    
     public void setPassword(String password) {
         this.password = password;
     }
    
     public boolean isAccountExpired() {
    	 return this.accountExpired;
     }
    
     public void setAccountExpired(boolean accountExpired) {
         this.accountExpired = accountExpired;
     }
    
     public boolean isAccountLocked() {
         return this.accountLocked;
     }
    
     public void setAccountLocked(boolean accountLocked) {
         this.accountLocked = accountLocked;
     }
    
     public boolean isPasswordExpired() {
         return this.passwordExpired;
     }
    
     public void setPasswordExpired(boolean passwordExpired) {
         this.passwordExpired = passwordExpired;
     }
    
     public boolean isEnabled() {
         return this.enabled;
     }
    
     public void setEnabled(boolean enabled) {
         this.enabled = enabled;
     }
    
     public Clob getDetails() {
         return this.details;
     }
    
     public void setDetails(Clob details) {
         this.details = details;
     }

     public Set<Vote> getVotes() {
         return this.votes;
     }
    
     public void setVotes(Set<Vote> votes) {
         this.votes = votes;
     }

    public Set<Document> getDocuments() {
        return this.documents;
    }
    
    public void setDocuments(Set<Document> documents) {
        this.documents = documents;
    }

    public Set<PeerKarmaParameter> getPeerKarmaParameters() {
        return this.peerKarmaParameters;
    }
    
    public void setPeerKarmaParameters(Set<PeerKarmaParameter> peerKarmaParameters) {
        this.peerKarmaParameters = peerKarmaParameters;
    }

    public Set<PeerAddress> getPeerAddresses() {
        return this.peerAddresses;
    }
    
    public void setPeerAddresses(Set<PeerAddress> peerAddresses) {
        this.peerAddresses = peerAddresses;
    }

	public void setVersion(String version) {
		this.version = version;
	}

	public String getVersion() {
		return version;
	}

	public void setPeerRole(Set<PeerRole> peerRole) {
		this.peerRole = peerRole;
	}

	public Set<PeerRole> getPeerRole() {
		return peerRole;
	}
	
	public Set<Role> getAuthorities() {
		Set<Role> roles = new HashSet<Role>(0);
		for (PeerRole role : peerRole) {
			roles.add(role.getRole());	
		}
		return roles;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setKarmaFiles(Set<KarmaFile> karmaFiles) {
		this.karmaFiles = karmaFiles;
	}

	public Set<KarmaFile> getKarmaFiles() {
		return karmaFiles;
	}
	
}


